package leetcode_1701_1800;

public class LeeCode_1793 {
    public static void main(String[] args) {

    }
    private static int maximumScore(int[] nums, int k) {
        int n = nums.length;
        int l = k, r = k, m1 = nums[k], m2 = nums[k];
        while (l >= 0){
            nums[l] = Math.min(nums[l], m1);
            m1 = nums[l];
            l--;
        }
        while (r < n){
            nums[r] = Math.min(nums[r], m2);
            m2 = nums[r];
            r++;
        }
        l = 0;
        r = n - 1;
        int ans = 0;
        while (l <= k && r >= k){
            int min = Math.min(nums[l], nums[r]);
            ans = Math.max(ans, min * (r - l + 1));
            if (nums[l] <= nums[r]){
                l++;
            }else {
                r--;
            }
        }
        return ans;
    }
}